package com.winhc.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class WXHttpUtil {
	
	public static String getUrlAString(String getUserInfoUrl) {
		String jsonUserStr = null;
		try {
			URL url1 = new URL(getUserInfoUrl); 
			HttpURLConnection urlConnection = (HttpURLConnection)url1.openConnection(); 

			// 将返回的输入流转换成字符串 
			InputStream inputStream = urlConnection.getInputStream(); 
			InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"UTF-8"); 
			BufferedReader in = new BufferedReader(inputStreamReader); 

			jsonUserStr = in.readLine().toString(); 

			System.out.println("jsonUserStr = "+jsonUserStr); 

			// 释放资源 
			inputStream.close(); 
			inputStream = null; 
			urlConnection.disconnect();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} 
		return jsonUserStr;

	}

}
